<template>
  <div id="selfBartendExtension">
    <c-title :hide="false" text="自助调酒收益"></c-title>
    <diyBackGround :customThemeBaseColor="'#F15353'" :minHeight="'8.5rem'">
      <div class="uesrBox" v-if="info && info.store">
        <img :src="info.store.avatar" class="uesrBoxImg" alt="" />
        <span class="userBoxName">{{ info.store.nickname }}</span>
      </div>
    </diyBackGround>
    <div class="contenBox">
      <div class="gridBox" v-if="info && info.statistic">
        <div class="gridItem">
          <div class="num">{{ info.statistic.total }}</div>
          <div class="txt">累计获得奖励（元）</div>
        </div>
        <div class="gridItem">
          <div class="num">{{ info.statistic.settled }}</div>
          <div class="txt">已结算金额（元）</div>
        </div>
        <div class="gridItem">
          <div class="num">{{ info.statistic.not_settle }}</div>
          <div class="txt">未结算金额（元）</div>
        </div>
      </div>
      <div class="tabBox">
        <van-tabs v-model="active" background="#f5f5f5" line-width="15px" @change="tabChange">
          <van-tab title="全部" name=""></van-tab>
          <van-tab title="已结算" name="1"></van-tab>
          <van-tab title="未结算" name="0"></van-tab>
        </van-tabs>
        <div class="list">
          <div class="lis" v-for="(item, index) in listData" :key="index" :class="{ pd: item.open }">
            <div class="lisTop">
              <div class="lis_l">{{ item.month }}</div>
              <div class="lis_r" @click="getMonthIncome(item.month, index)">
                {{ $i18n.t("money") }}{{ item.total_amount }}
                <i class="iconfont icon-icon_down1" v-if="!item.open"></i>
                <i class="iconfont icon-icon_up1" v-if="item.open"></i>
              </div>
            </div>
            <div class="listHide" v-if="item.open">
              <div class="listHide_ls" v-for="(items, ind) in item.detail" :key="ind">
                <div class="listHide_ls_t">
                  <div class="listHide_ls_line">{{ items.order_sn }}</div>
                  <div class="listHide_ls_line">{{ $i18n.t("money") }}{{ items.amount }}</div>
                </div>
                <div class="listHide_ls_t">
                  <div class="listHide_ls_line dline">时间：{{ items.created_at }}</div>
                  <div class="listHide_ls_line dline">{{ items.settle_name }}</div>
                </div>
              </div>
              <div class="tapMore" v-if="item.page < item.total_page" @click="tapMore(item, index)">点击加载更多</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import diyBackGround from "../../components/diyBackGround.vue";
export default {
  data() {
    return {
      active: 0,
      info: null,
      listData: []
    };
  },
  components: { diyBackGround },
  activated() {
    this.init();
    this.getData();
    this.getGroup();
  },
  methods: {
    init() {
      this.page = 1;
      this.total_page = 0;
      this.listData = [];
    },
    async getData() {
      let { data, msg, result } = await $http.post("plugin.self-bartending.api.common.income.index", {}, ".");
      if (result) {
        this.info = data;
      } else {
        this.$toast(msg);
      }
    },
    tabChange() {
      this.init();
      this.getGroup();
    },
    async getGroup() {
      let { data, msg, result } = await $http.post("plugin.self-bartending.api.common.income.order-group", { status: this.active }, "");
      if (result) {
        this.listData = data;
      } else {
        this.$toast(msg);
      }
    },
    async getMonthIncome(month, index) {
      if (this.listData[index].open) {
        this.$set(this.listData[index], "open", false);
        return;
      }
      this.$set(this.listData[index], "open", true);
      let { data, msg, result } = await $http.post("plugin.self-bartending.api.common.income.order", { status: this.active, month: month }, "");
      if (result) {
        this.$set(this.listData[index], "detail", data.data);
        this.$set(this.listData[index], "total_page", data.last_page);
        this.$set(this.listData[index], "page", data.current_page);
      } else {
        this.$toast(msg);
      }
    },
    async tapMore(item, index) {
      if (item.page >= item.total_page) return;
      let json = { status: this.active, month: item.month, page: item.page + 1 };
      let { data, msg, result } = await $http.post("plugin.self-bartending.api.common.income.order", json, "");
      if (result) {
        this.$set(this.listData[index], "detail", [...this.listData[index].detail, ...data.data]);
        this.$set(this.listData[index], "total_page", data.last_page);
        this.$set(this.listData[index], "page", data.current_page);
      } else {
        this.$toast(msg);
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.tapMore {
  line-height: 3rem;
  text-align: center;
}
#selfBartendExtension {
  padding-bottom: 2rem;
  .contenBox {
    margin: 0 0.75rem;
    margin-top: -2.94rem;
    .tabBox {
      .list {
        padding: 0 0.94rem;
        box-sizing: border-box;
        background: #ffffff;
        border-radius: 0.5rem;
        margin-top: 0.66rem;
        .pd {
          padding-bottom: 0.66rem;
        }
        .lis {
          .listHide {
            background: #fafafa;
            border-radius: 0.63rem;
            padding: 0 1.16rem 0 0.72rem;
            box-sizing: border-box;
            .listHide_ls {
              padding: 0.66rem 0;
              box-sizing: border-box;
              border-bottom: 1px solid #f0f0f1;
              .listHide_ls_t {
                margin-bottom: 0.4rem;
                display: flex;
                justify-content: space-between;
                .listHide_ls_line {
                  font-weight: 500;
                  font-size: 0.81rem;
                  color: #00001c;
                }
                .dline {
                  font-size: 0.75rem;
                  color: #6e6e79;
                  line-height: 0.83rem;
                }
              }
              .listHide_ls_t:last-child {
                margin-bottom: 0;
              }
            }
            .listHide_ls:last-child {
              border-bottom: 0;
            }
          }
          .lisTop {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1rem 0;
            box-sizing: border-box;
            .lis_l {
              font-weight: 500;
              font-size: 0.88rem;
            }
            .lis_r {
              font-size: 0.88rem;
              display: flex;
              align-items: center;
              .iconfont {
                color: #aaaab3;
                font-size: 0.7rem;
                margin-left: 0.35rem;
              }
            }
          }
        }
      }
    }
    .gridBox {
      background: #ffffff;
      border-radius: 0.5rem;
      display: grid;
      grid-template-columns: 33.33% 33.33% 33.33%;
      padding: 1.09rem 0.35rem;
      box-sizing: border-box;
      .gridItem {
        text-align: center;
        .num {
          font-weight: bold;
          font-size: 0.94rem;
          color: #00001c;
          margin-bottom: 0.4rem;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .txt {
          font-size: 0.75rem;
          color: #6e6e79;
        }
      }
    }
  }
  .uesrBox {
    display: flex;
    align-items: center;
    margin-top: 0.81rem;
    margin-left: 1.06rem;
    .uesrBoxImg {
      margin: 0;
      margin-right: 0.53rem;
      width: 3.44rem;
      height: 3.44rem;
      border-radius: 50%;
    }
    .userBoxName {
      font-weight: bold;
      font-size: 1rem;
      color: #ffffff;
    }
  }
}
</style>
